// JavaScript Document

;$(function() 
{
	
	'use strict';
	var sidebar = $('#sidebar'),
     mask= $('.mask'),
	 sidebar_trigger=$('#sidebar_trigger'),
	 backbutton=$('.back'),
	 sidebar_trigger2=$('#sidebar_trigger2');
	 
     function showsidebar()
	 {
		 mask.fadeIn();
		 sidebar.css('right',0);
		 }
	function hidesidebar() 
	{mask.fadeOut();
	sidebar.css('right',-sidebar.width());
		}
	function backtotop(){
		$('body').animate({
			scrollTop:0
			},800);
		}
     sidebar_trigger.on('click',showsidebar)
	 mask.on('click',hidesidebar)
	 sidebar_trigger2.on('click',showsidebar)
	 mask.on('click',hidesidebar)
	 backbutton.on('click',backtotop)
	
	 $(window).on('scroll',function(){
		
		if($(window).scrollTop() > $(window).height())
		{
			backbutton.fadeIn();
			sidebar.fadeOut();
		}
			else
			{
			backbutton.fadeOut();
			sidebar.fadeIn();
			}
		});
	$(window).trigger('scroll');
	 
	
})